//
//  MyKeyCaseCell.m
//  PropertyMananger
//
//  Created by bh on 17/3/8.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "MyKeyCaseCell.h"

@implementation MyKeyCaseCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * CellID = @"MyKeyCaseCellID";
    MyKeyCaseCell * cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (!cell) {
        
        cell = [[MyKeyCaseCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.unitLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.unitLabel];
        self.unitLabel.text = @"1栋1单元门";
        
        self.unitLabel.textColor = BHColor(51, 51, 51);
        self.unitLabel.font = BHFont(15);
        self.unitLabel.textAlignment = NSTextAlignmentLeft;
        
        [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).with.offset(15);
            make.top.equalTo(self).with.offset(15);
            make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 25));
        }];

        UIImageView * timeImg = [[UIImageView alloc]init];
        [self.contentView addSubview:timeImg];
        timeImg.image = IMG(@"ico_key_time");
        
        [timeImg mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.leading.equalTo(self.contentView).with.offset(15);
            make.top.equalTo(self.unitLabel.mas_bottom).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        
        self.timeLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.timeLabel];
        
        self.timeLabel.text = @"有效期:2017-3-4";
        self.timeLabel.textColor = BHColor(102, 102, 102);
        self.timeLabel.textAlignment = NSTextAlignmentLeft;
        self.timeLabel.font = BHFont(15);
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(timeImg.mas_trailing).with.offset(0);
            make.centerY.equalTo(timeImg).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(140, 25));
        }];
        
        UIImageView * statusImg = [[UIImageView alloc]init];
        [self.contentView addSubview:statusImg];
        statusImg.image = IMG(@"ico_key_state");
        
        [statusImg mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.leading.equalTo(self.timeLabel.mas_trailing).with.offset(5);
            make.top.equalTo(timeImg).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        
        self.stateLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.stateLabel];
        
        self.stateLabel.text = @"状态:正常";
        self.stateLabel.textColor = BHColor(102, 102, 102);
        self.stateLabel.textAlignment = NSTextAlignmentLeft;
        self.stateLabel.font = BHFont(15);
        
        [self.stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(statusImg.mas_trailing).with.offset(5);
            make.centerY.equalTo(statusImg).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(70, 25));
        }];

        
        self.keyCaseButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.keyCaseButton];
        
        [self.keyCaseButton setImage:IMG(@"ico_key") forState:UIControlStateNormal];
        [self.keyCaseButton setTitle:@"去开门" forState:UIControlStateNormal];
        self.keyCaseButton.titleLabel.font = BHFont(13);
        [self.keyCaseButton setTitleColor:BHColor(102, 102, 102) forState:UIControlStateNormal];
        
       [self.keyCaseButton setTitleEdgeInsets:UIEdgeInsetsMake(65, -50, 0, 0)];
        
        [self.keyCaseButton mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.trailing.equalTo(self.contentView).with.offset(0);
            make.top.equalTo(self.contentView).with.offset(15);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];


        
    }

    return self;
}
- (void)setModel:(MDkeyModel *)model{
    
    MDkeyModel * mdModel = [[MDkeyModel alloc]init];
    
    mdModel = model;
    DLog(@"====%@",model.DeviceName);
    self.unitLabel.text = model.DeviceName;
    
    NSArray * timeArr = [model.ExpireTime componentsSeparatedByString:@" "];
    self.timeLabel.text = [NSString stringWithFormat:@"有效期:%@",timeArr[0]];

}
@end
